package com.itqf.ipmsys.utils;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;

import java.io.IOException;

/**
 * @author corn
 * @create 2021-09-07 10:19
 * @Description: json处理的工具类
 */
public class JSONUtil {
    private static final ObjectMapper OBJECTMAPPER = new ObjectMapper();

    public static String  Obj2JSON(Object obj){
        try {
            return OBJECTMAPPER.writeValueAsString(obj);
        } catch (JsonProcessingException e) {
            e.printStackTrace();
        }
        return null;
    }


    public static <T> T json2Obj(String json, Class<T> clazz){
        T t = null;

        try {
            t = OBJECTMAPPER.readValue(json, clazz);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return t;
    }

}
